<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">我的计分</block>
		</cu-custom>	
		<uni-section title="基本信息" type="line">
			<uni-list>
				<uni-list-item  title="姓名" :rightText="person.name"></uni-list-item>
				<uni-list-item  title="工龄" :rightText="person.workAge"></uni-list-item>
				<uni-list-item  title="总分" :rightText="sum"></uni-list-item>
			</uni-list>
		</uni-section>
		<!-- <employeeScoreItem :data-msg="categorys" v-on:childSum="childSum" :data-fab="isinsert" :data-sum="sum - 0" :del-list="imgList"></employeeScoreItem> -->
		<button class="myfabbtn" @click="fabClick()">
			<uni-icons v-if="isinsert" color="#fff" type="plusempty" size="30"></uni-icons>
			<uni-icons v-else color="#fff" type="closeempty" size="30"></uni-icons>
		</button>
	</view>
</template>

<script>
	import employeeScoreItem from "../../component/myComponents/employeeScoreItem.vue"
	export default {
		components:{
			employeeScoreItem
		},
		name: "getScore",
		data() {
			return {
				// showModal: false,
				isinsert: true,
				flag:0,
				tableData:[],
				person:{
					name: '史蒂文',
					workAge: '5',
					apartment: '信息部',
					marry: '已婚',
					address: 'xxx区xx',
					other: 'xxxxx',
				},
				imgList: [],
				sum: "0",
				categorys: [],
				project_id: "",
				totalItem: [],
			}
		},
		onLoad: function () { //option为object类型，会序列化上个页面传递的参数
			// console.log(this.$Route.query)
			this.project_id = this.$Route.query.id
		},
		mounted() {
			this.$http.post(`/base/znzfEmployeeScoreItem/queryLatestScoreByUserId?userId=${this.$store.getters.userid}`).then(res => {
				// console.log(res.data.result)
				this.sum = res.data.result.toString()
			})
			// console.log(this.$store.getters.userid)
			this.$http.get(`/base/znzfEmployee/searchByUid?userId=${this.$store.getters.userid}`).then(res => {
				// console.log(1,res)
				let people = res.data.result;
				this.$http.get(`/sys/sysDepart/getDepartName?orgCode=${people.sysOrgCode}`).then(res => {
					// console.log(res.data.result.departName)
					this.person.name = people.name;
					this.person.workAge = people.seniority.toString();
					this.person.apartment = res.data.result.departName;
					this.person.marry = people.ismarried == 0 ? '未婚':'已婚';
					this.person.address = people.address;
					this.person.other = 'xxxxx';
				})
			})
			this.$http.get(`/base/znzfScoreStandard/list`).then(res => {
				// console.log(3,res,res.data.result.records)
				let temp = [];
				let flag = false,count = 0;
				res.data.result.records.forEach(category => {
					let temp = {
						id: category.id,
						title: category.title,
						items: [],
						isShow: false,
					}
					this.$http.get(`/base/znzfScoreStandard/queryZnzfScoreStandardItemByMainId?id=${category.id}`).then(res => {
						// console.log(4,res,res.data.result)
						res.data.result.forEach((item,index) => {
							let temp1 = {
								id: item.id,
								index: index+1,
								score: item.score,
								name: item.name,
								ishas: false,
								opinion: null,
								approvalPeople:null,
								approvalTime: null,
								note: null,
								ssiname: null,
								ssinote: null,
								ssiscore: null,
								appendix: [],
								state: "-1",
							}
							temp.items.push(temp1)
						})
					})
					this.categorys.push(temp)
				})
				console.log(this.categorys)
				this.init()
			})
		},
		methods: {
			init() {
				this.$http.post(`/base/znzfEmployeeScoreItem/getEmployeeScoreItemList?userId=${this.$store.getters.userid}`).then(res => {
					console.log(5,res.data.result)
					this.imgList = [],this.totalItem = [];
					res.data.result.forEach(itemAppendix => {
						// let temp2 = {
						// 	id: itemAppendix.scoreItemId,
						// 	appendix: itemAppendix.appendix,
						// 	delId: itemAppendix.id,
						// }
						this.imgList.push(itemAppendix)
					})
					console.log(this.imgList)
					for(let img of this.imgList) {
						for(let category of this.categorys) {
							// console.log(category)
							for(let item of category.items) {
								if(item.id == img.scoreItemId) {
									item.ishas = true
									category.isShow = true
									item.opinion = img.opinion
									item.approvalPeople = img.approvalPeople
									item.approvalTime = img.approvalTime
									item.note = img.note
									item.ssiname = img.ssiname
									item.ssinote = img.ssinote
									item.ssiscore = img.ssiscore
									item.state = img.state
									if(img.appendix.length) {
										item.appendix = img.appendix.split(",")
										// this.totalItem.push({name:item.name,score:item.score})
									}else {
										item.appendix = ""
									}
								}
							}
						}
					}
					// console.log(this.categorys,this.totalItem)
				})
			},
			fabClick() {
				let str = ""
				if(this.isinsert) str = "显示全部计分项"
				else str = "显示已选计分项"
				uni.showToast({
					title: str,
					icon: 'none'
				})
				this.isinsert = !this.isinsert;
			},
			childSum(e) {
				// console.log(e)
				this.sum = e.sum.toString()
				// console.log(this.sum)
				if(e.flag)this.init()
			},
		}
	}
</script>

<style lang='scss'>
.myfabbtn{
	position: fixed;
	left: 8px;
	bottom: 16px;
	border-radius: 50%;
	border: none;
	background-color: #8cde9b;
	width: 50px;
	height: 50px;
	display: flex;
	justify-content: center;
	align-items:center;
	z-index: 100;
}
.myfootbtn{
	margin: 8px 5%;
	width: 90%;
}
</style>
